//
//  TableViewController.m
//  searchController
//
//  Created by mac on 16/10/26.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "TableViewController.h"
#import "NSArray+Filter.h"
@interface TableViewController ()
{
    NSArray *arr;
}
@end

@implementation TableViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
}


- (NSMutableAttributedString *)dyeingString:(NSString *)string attributedString:(NSMutableAttributedString *)attriString
{
    for(NSInteger i = 0; i < string.length; i++)
    {
        if([self.serchStr containsString:[string substringWithRange:NSMakeRange(i, 1)]])
        {
            [attriString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(i, 1)];
            [attriString addAttribute:NSBackgroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(i, 1)];
        }
    }
    return attriString;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:self.data[indexPath.row]];
    
    cell.textLabel.attributedText = [self dyeingString:self.data[indexPath.row] attributedString:attriString];
    
    return cell;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
